#include "cleardataservice.h"
#include "appchat/accountmanager.h"
#include "contact/contactmanager.h"
#include "converse/conversemanager.h"
#include "notify/notifymanager.h"


namespace Service {

ClearDataService *ClearDataService::m_instance = NULL;

ClearDataService::ClearDataService(QObject *parent) :
    QObject(parent)
{
    init();
}


ClearDataService *ClearDataService::instance(QObject *parent)
{
    if (m_instance == NULL)
        m_instance = new ClearDataService(parent);
    return m_instance;
}


void ClearDataService::init()
{
    setConnection();
}


void ClearDataService::setConnection() const
{
    connect(AccountManager::instance(), &AccountManager::logouted,
            this, &ClearDataService::onLogouted);
}


void ClearDataService::onLogouted()
{
    Notify::Manager::instance()->clearData();
    Converse::Manager::instance()->clearData();
    Contact::Manager::instance()->clearData();
    AccountManager::instance()->clearData();
}

} // namespace Service
